package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.AttendReportAddDTO;
import org.jsola.hr.dto.AttendReportUpdateDTO;
import org.jsola.hr.entity.AttendReportDO;
import org.jsola.hr.query.AttendReportQuery;
import org.jsola.hr.service.IAttendReportService;
import org.jsola.hr.vo.AttendReportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendReportTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendReportService attendReportService;

    /**
     * 生成add测试数据
     * @return AttendReportAddDTO
     */
    public AttendReportAddDTO getAttendReportAddDTO(){
        AttendReportAddDTO attendReportAddDTO = new AttendReportAddDTO();
        attendReportAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendReportAddDTO.setCompanyName(getRandomValue("varchar",100));
        attendReportAddDTO.setDeptId(getRandomValue("varchar",32));
        attendReportAddDTO.setDeptName(getRandomValue("varchar",100));
        attendReportAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        attendReportAddDTO.setEmpInfoId(getRandomValue("varchar",32));
        attendReportAddDTO.setEmpInfoName(getRandomValue("varchar",50));
        return attendReportAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendReportUpdateDTO
     */
    public AttendReportUpdateDTO getAttendReportUpdateDTO(AttendReportVO attendReportVO){
        return attendReportService.selectDOById(attendReportVO.getId(), SITE_ID).to(AttendReportUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendReportQuery
     */
    public AttendReportQuery getAttendReportQuery() {
        AttendReportQuery attendReportQuery = new AttendReportQuery();
        List<AttendReportDO> attendReportDOList = attendReportService.list(new AttendReportDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendReportDOList)) {
            AttendReportDO attendReportDO = attendReportDOList.get(0);
            attendReportQuery = attendReportDO.to(AttendReportQuery.class);
            if (attendReportDO.getGmtCreate() != null) {
                attendReportQuery.setGmtCreateStart(DateKit.getBeforeDay(attendReportDO.getGmtCreate(),-1));
                attendReportQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendReportDO.getGmtCreate(),1));
            }
            if (attendReportDO.getGmtModified() != null) {
                attendReportQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendReportDO.getGmtModified(),-1));
                attendReportQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendReportDO.getGmtModified(),1));
            }
        }
        return attendReportQuery;
    }

    /**
     * 保存示例
     * @return AttendReportVO
     */
    public AttendReportVO saveAttendReportExample(){
        AttendReportAddDTO addDTO = this.getAttendReportAddDTO();
        AttendReportVO attendReportVO = attendReportService.save(addDTO,buildTokenUser());
        return attendReportVO;
    }


}

